package com.five.api.service.impl;

import com.five.api.dao.StudyTraceMapper;
import com.five.api.service.StudyTraceService;
import com.five.entity.StudyTrace;
import com.five.qo.PageQO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: star
 * @Date: 2021-05-21 14:23
 * 学习足迹Service 实现类
 */
@Service
public class StudyTraceServiceImpl implements StudyTraceService {

    @Autowired
    private StudyTraceMapper studyTraceMapper;

    @Override
    public List<StudyTrace> selectStudyTraces(Long userId) {
        List<StudyTrace> studyTraces = studyTraceMapper.selectStudyTraces(userId);
        return studyTraces;
    }

    @Override
    public List<StudyTrace> selectStudyTracesPage(PageQO pageQO) {
        pageQO.setPage((pageQO.getPage()-1)*pageQO.getPageSize());
        List<StudyTrace> studyTraces = studyTraceMapper.selectStudyTracesPage(pageQO);
        return studyTraces;
    }

    @Override
    @Transactional
    public int insertStudyTracesPage(StudyTrace studyTrace) {
        StudyTrace checkStudyTrace = studyTraceMapper.checkStudyTraces(studyTrace);
        if(checkStudyTrace == null){
            return studyTraceMapper.insertStudyTraces(studyTrace);
        }
        return 1;
    }
}
